from typing import List, Union, Literal, Dict, Optional


class Trigger:
    prefix: List[str] = [""]
    """全局的触发响应前缀，同时适用于私聊和群聊，默认不需要"""
    prefix_friend: List[str] = []
    """私聊中的触发响应前缀，默认不需要"""
    prefix_group: List[str] = []
    """群聊中的触发响应前缀，默认不需要"""

    prefix_ai: Dict[str, List[str]] = {}
    """特定类型 AI 的前缀，以此前缀开头将直接发消息至指定 AI 会话"""

    require_mention: Literal["at", "mention", "none"] = "at"
    """群内 [需要 @ 机器人 / 需要 @ 或以机器人名称开头 / 不需要 @] 才响应（请注意需要先 @ 机器人后接前缀）"""
    reset_command: List[str] = ["重置会话"]
    """重置会话的命令"""
    rollback_command: List[str] = ["回滚会话"]
    """回滚会话的命令"""
    prefix_image: List[str] = ["画", "看"]
    """图片创建前缀"""
    switch_model: str = r"切换模型 (.+)"
    """切换当前上下文的模型"""
    switch_command: str = r"切换AI (.+)"
    """切换AI的命令"""
    switch_voice: str = r"切换语音 (.+)"
    """切换tts语音音色的命令"""
    mixed_only_command: List[str] = ["图文混合模式"]
    """切换至图文混合模式"""
    image_only_command: List[str] = ["图片模式"]
    """切换至图片回复模式"""
    text_only_command: List[str] = ["文本模式"]
    """切换至文本回复模式"""
    ignore_regex: List[str] = []
    """忽略满足条件的正则表达式"""
    allowed_models: List[str] = [
        "gpt-3.5-turbo",
        "gpt-3.5-turbo-0301",
        "text-davinci-002-render-sha",
        "text-davinci-002-render-paid"
    ]
    """允许普通用户切换的模型列表"""
    allow_switching_ai: bool = True
    """允许普通用户切换AI"""
    ping_command: List[str] = ["ping"]
    """获取服务状态"""

    # 获取token总量
    get_token_total_command: List[str] = ["获取token总量"]
    # 获取当前预设
    get_preset_command: List[str] = ["获取当前预设"]


class SessionHolder:
    reset_threshold: float = 0.5


class Preset:
    command: str = r"加载预设 (\w+)"
    keywords: dict[str, str] = {}
    loaded_successful: str = "预设加载成功！"
    scan_dir: str = "./presets"
    hide: bool = False
    """是否禁止使用其他人 .预设列表 命令来查看预设"""


class Idempotent:
    # 回复消息幂等
    replay_expire_time: int = 60 * 60

    # 进群消息幂等
    group_join_expire_time: int = 60 * 60


class LarkUrl:
    send_message_url: str = "https://open.feishu.cn/open-apis/im/v1/messages?receive_id_type=chat_id"
    get_token_url: str = "https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal/"
    relay_message_url: str = "https://open.feishu.cn/open-apis/im/v1/messages/%s/reply"
    get_chat_info_url: str = "https://open.feishu.cn/open-apis/im/v1/chats/%s"


class Config:
    trigger: Trigger = Trigger()
    sessionHolder: SessionHolder = SessionHolder()
    preset: Preset = Preset()
    idempotent: Idempotent = Idempotent()
    larkUrl: LarkUrl = LarkUrl()
